<link rel="stylesheet" type="text/css" href="/assets/third-party/datatables/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="/assets/css/dataTables.bootstrap.css">
<link rel="stylesheet" type="text/css" href="/assets/third-party/bootstrap-datetimepicker-master/css/bootstrap-datetimepicker.min.css">

<style type="text/css">
	.il{
		display: inline;
	}
</style>

<div class="container" style="margin-top: 60px;">
	<div class="row">
		<div class="col-lg-12">
			<form action="/admin/node">
			<input type="text" name="start_at" placeholder="发布起始时间" value="<?php echo \Input::get('start_at', ''); ?>" class="form-control il" style="width: 160px;" role="datetime"> 
			- <input type="text" name="end_at" placeholder="发布结束时间" value="<?php echo \Input::get('end_at', ''); ?>" class="form-control il" style="width: 160px;" role="datetime"> 
			<select name="cid" class="form-control il" style="width: 140px;">
				<option value="<?php echo $cat->id ?>">全部<?php echo $cat->id == 1 ? "" : "课程"; ?></option>
				<?php foreach ($cats as $key => $value) { ?>
					<option value="<?php echo $value->id; ?>"<?php echo \Input::get('cid', false) == $value->id ? ' selected="selected"' : '';?>><?php echo $value->name; ?></option>
				<?php } ?>
			</select>
			<button type="submit" class="btn btn-info"> <i class="fa fa-search"></i> 查询</button>
			<a href="/admin/node/create/<?php echo $category_id;?>" class="btn btn-success"> <i class="fa fa-plus"></i> 发布 </a>
			<!--<a href="#" class="btn btn-success"> <i class="fa fa-plus"></i> 全选 </a>
			<a href="#" class="btn btn-danger"> <i class="fa fa-plus"></i> 批量删除 </a>
			<a href="#" class="btn btn-danger"> <i class="fa fa-plus"></i> 刷新 </a>-->
			</form>
		</div>
	</div>
	<div class="row" style="margin-top: 10px;">
		<div class="col-lg-12">
			<div class="panel panel-default">
                <div class="panel-heading">
                    <?php echo \Input::get('cid', 1) == 1 ? '动态' : '教师风采'; ?>列表
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
					<table class="table table-bordered table-hover">
						<thead>
							<tr>
								<th>ID</th>
								<th><?php echo in_array(\Input::get('cid', 1), array(10, 11)) ? '缩略图' : '头像'; ?></th>
								<th><?php echo in_array(\Input::get('cid', 1), array(10, 11)) ? '标题' : '教师姓名'; ?></th>
								<th><?php echo in_array(\Input::get('cid', 1), array(10, 11)) ? '分类' : '教授科目'; ?></th>
								<?php if(in_array(\Input::get('cid', 1), array(10, 11))){ ?>
								<th>阅读数次</th>
								<?php } ?>								
								<th>发布时间</th>
								<th>发布人</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach ($items as $key => $value) { ?>
							<tr data-id="<?php echo $value->id; ?>">
								<td><?php echo $value->id; ?></td>
								<td><img src="<?php echo $value->thumbnail ? $value->thumbnail : '/assets/img/demo.jpg'; ?>" alt="缩略图" style="width: 80px;" /></td>
								<td><?php echo $value->title; ?></td>
								<td><?php echo in_array(\Input::get('cid', 1), array(10, 11))? $value->category->name : $value->category->name; ?></td>
								<?php if(in_array(\Input::get('cid', 1), array(10, 11))){ ?>
								<td><?php echo $value->view_total; ?></td>
								<?php } ?>
								<td><?php echo date('Y-m-d H:i:s', $value->created_at); ?></td>
								<td><?php echo $value->author ? $value->author->username : ''; ?></td>
								<td>
									<a class="btn btn-sm btn-info" role="edit"> <i class="fa fa-pencil-square-o"></i> 编辑</a>
									<a data-toggle="modal" data-target="#confirmModal" class="btn btn-sm btn-danger"> <i class="fa fa-trash-o"></i> 删除</a>
									<!--<a href="#" class="btn btn-sm btn-success"> <i class="fa fa-arrow-up"></i> 置顶</a>-->
								</td>
							</tr>
							<?php } ?>
							
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>


<!-- 确认删除模态框 -->
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalTitle" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-body">
				<div class="alert alert-warning">
					<strong>确定删除？</strong>
					<p>删除该记录，该记录将无法被查找到!</p>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal"> 取消 </button>
				<button type="button" id="btnConfirm" class="btn btn-danger"> 确定 </button>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript" src="/assets/third-party/datatables/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/assets/js/dataTables.bootstrap.js"></script>
<script type="text/javascript">
	var flag = false;

	$(function(){
		$('.table').dataTable({
	        "oLanguage": {
	            "sLengthMenu": "每页显示 _MENU_ 条记录",
	            "sZeroRecords": "很抱歉，未找到相关数据",
	            "sInfo": "从 _START_ 至 _END_ /共 _TOTAL_ 条数据",
	            "sInfoEmpty": "没有符合条件的数据",
	            "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
	            "sSearch": "搜索：",
	            "oPaginate": {  
					"sFirst": "首页",  
					"sPrevious": "上一页",
					"sNext": "下一页",
					"sLast": "末页"
				}  
	        },
	        fnDrawCallback: function(){

	            if(window.flag == false){
	        		window.flag = true;
	        		var index = localStorage.getItem('pagination_index');
	                localStorage.removeItem('pagination_index');
		        	if( ! index){
		        		index = 1;
		        	}
		        	index -= 1;

		        	$('.table').dataTable().fnPageChange(index);
	                
	        	}
            }
	    });

		$('table').delegate('a[data-target="#confirmModal"]', 'click', function(){
			$('#btnConfirm').attr('data-id', $(this).parent().parent().attr('data-id'));	    	
	    });

		$('table').delegate('a[role="edit"]', 'click', function(){
			localStorage.setItem('pagination_index', $('.pagination .active').find('a').text());
			window.location.href = "/admin/node/edit/" + $(this).parents('tr').attr('data-id');
	    });

	    $('#btnConfirm').click(function(){
	    	window.location.href = "/admin/node/delete/" + $(this).attr('data-id');
	    });
	});
</script>

<script type="text/javascript" src="/assets/third-party/bootstrap-datetimepicker-master/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/assets/third-party/bootstrap-datetimepicker-master/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
$(function(){
	$('input[role="datetime"]').datetimepicker({
		language: 'zh-CN'
	});
});
</script>